﻿@model Controller2.Models.Admin.AdminViewModel
@{
    ViewBag.Title = "Administração de Usuários: Membership";
}
<!DOCTYPE html>
<html class="no-js">
<head>
    <title>Membership Admin</title>
    <script src="@Url.Content("~/Scripts/jquery.validate.min.js")" type="text/javascript"></script>
    <script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.min.js")" type="text/javascript"></script>
    <style type="text/css">
        table {
            border: solid 1px #99a6b3;
            border-collapse: collapse;
            font-size: 0.8em;
            margin-top: 30px;
        }

            table tbody tr:nth-child(odd) {
                background-color: #fff;
            }

            table tbody tr:nth-child(even) {
                background-color: #F7F7F7;
            }

            table tbody tr:hover {
                background-color: #eae4e4;
            }

            table tbody tr.selected {
                background-color: #e1d7d7;
            }

            table td {
                padding: 5px;
                border: solid 1px #e8eef4;
                color: #000;
            }

            table th {
                padding: 6px 5px;
                text-align: left;
                background-color: #e8eef4;
                border: solid 1px #99a6b3;
            }

            table tbody tr td {
                padding: 3px 0 0 0;
                height: 20px;
                line-height: 20px;
                vertical-align: bottom;
            }

            table tfoot tr td {
                font-size: 1.1em;
                font-weight: bold;
                padding: 6px 4px 0 0;
                height: 24px;
                line-height: 24px;
                vertical-align: bottom;
            }

            table tbody tr td, table tfoot tr td {
                border: solid 1px #adbdcc;
                border-collapse: collapse;
            }

        .grid {
            min-width: 900px;
            width: 100%;
            margin: auto;
        }

        .usuario-header, .usuario {
            padding-left: 5px;
            width: 120px;
        }

        .email-header, .email {
            padding-left: 5px;
        }

        .isOnline-header, .isOnline {
            padding-left: 5px;
            width: 100px;
        }

        .aprovado-header, .aprovado {
            text-align: center;
            width: 45px;
        }

        .travado-header, .travado {
            text-align: center;
            width: 45px;
        }

        .senha-header, .senha {
            text-align: center;
            width: 60px;
        }

        .regras-header, .regras {
            padding-left: 5px;
            width: 200px;
        }

        .opcoes-header, .opcoes {
            width: 50px;
            text-align: center;
            padding: 0;
        }

        #novo {
            font-size: 1.8em;
            padding: 20px;
        }

        #roles {
            margin: 20px;
        }

        .headline {
            margin-bottom: 20px;
            font-size: 20px;
        }

        a.yes:link, a.yes:visited, a.yes:active {
            text-decoration: none;
            color: #008000;
            font-weight: bold;
        }

        a.yes:hover {
            color: #036103;
        }

        a.no:link, a.no:visited, a.no:active {
            text-decoration: none;
            color: #f00;
            font-weight: bold;
        }

        a.no:hover {
            color: #af0606;
        }
    </style>
</head>
<body>
    @if (Model.Users.Count > 0)
    {
        <table class="grid">
            <thead>
                <tr>
                    <th colspan="9" id="novo">Usuários
                    </th>
                </tr>
                @if (TempData["UserError"] != null)
                {
                    <tr>
                        <th colspan="9">
                            <span class="field-validation-error">@TempData["UserError"]</span>
                        </th>
                    </tr>
                }
                <tr>
                    <th class="usuario-header">Usuário
                    </th>
                    <th class="email-header">Email
                    </th>
                    <th class="isOnline-header">On/Off
                    </th>
                    <th class="aprovado-header">Aprov.
                    </th>
                    <th class="travado-header">Travado
                    </th>
                    <th class="senha-header">Senha
                    </th>
                    <th class="regras-header">Regras
                    </th>
                    <th class="opcoes-header"></th>
                </tr>
            </thead>
            <tbody>
                @foreach (MembershipUser user in Model.Users)
                {
                    <tr>
                        <td class="usuario">
                            @Html.Encode(user.UserName)
                        </td>
                        <td class="email">
                            @Html.Encode(user.Email)
                        </td>
                        @if (user.IsOnline)
                        {
                            <td class="isOnline">Online
                            </td>
                        }
                        else
                        {
                            <td class="isOnline">
                                @{ var offlineSince = Math.Floor((DateTime.Now - user.LastActivityDate).TotalDays) + " days."; }
                                Offline - @offlineSince
                            </td>
                        }
                        <td class="aprovado">
                            @{ 
                        var isApproved = user.IsApproved ? "Sim" : "Não";
                        var classe = user.IsApproved ? "yes" : "no"; 
                            }
                            @if (!user.UserName.Equals("masterAdmin"))
                            {
                                <a href='@Url.Action("ToggleApproved", "Account", new { userName = user.UserName })' class="@classe">
                                    @isApproved
                                </a>                               
                            }
                        </td>
                        <td class="travado">
                            @if (!user.UserName.Equals("masterAdmin"))
                            {
                                if (user.IsLockedOut)
                                {
                                @Html.ActionLink("Sim", "UnlockUser", "Account", null, new { userName = user.UserName, @class = "no" })
                                }
                                else
                                {
                                    var isLockedOut = user.IsLockedOut ? "Sim" : "Não"; 
                                @isLockedOut
                                }
                            }
                        </td>
                        <td class="senha">
                            @if (!user.UserName.Equals("masterAdmin"))
                            {
                                <a href='@Url.Action("ResetPassword", "Account", new { userName = user.UserName })'>Gerar Nova</a>
                            }
                        </td>
                        <td class="regras">
                            @if (!user.UserName.Equals("masterAdmin"))
                            {
                                foreach (string role in Model.Roles)
                                {
                                    string rolesForUser = string.Join(",", Roles.GetRolesForUser(user.UserName));
                                    classe = rolesForUser.Contains(role) ? "yes" : "no";
                                <span><a href='@Url.Action("ToggleRole", "Account", new { role = role, userName = user.UserName })' class="@classe" >@Html.Encode(role)</a>
                                </span>
                                }
                            }
                            else
                            {
                                <text>SysAdmin</text>
                            }
                        </td>
                        <td class="opcoes">
                            @if (!user.UserName.Equals("masterAdmin"))
                            {
                                <a class="delete" href='@Url.Action("DeleteUser", "Account", new { userName = user.UserName })'>Excluir</a>
                            }
                        </td>
                    </tr>
                }
            </tbody>
        </table>
    }
    else
    {
        <p>
            Nenhum usuário registrado.
        </p>
    }
    @*<div id="roles">
        <h1 class="headline">Regras</h1>
        <div>
            <ul>
                @foreach (string role in Model.Roles)
                {
                    <li>@Html.Encode(role)
                        @if (role != "Admin")
                        { 
                            <text> [ <a class="delete" href="@Url.Action("DeleteRole", "Account", new { role = role })">
                                delete</a> ]
                            </text>
                        } </li>
                }
            </ul>
        </div>
    </div>*@
    <script type="text/javascript">
        $(function () {
            hideLoading();
            // verify the delete intent
            $(".delete").click(function (e) {
                if (!confirm("Tem certeza que deseja excluir este registro?")) {
                    return false;
                }
                return true;
            });
        });
    </script>
</body>
</html>
